<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
define('VIDEO_CAT', 17);
define('STYLE_CAT', 18);

class Blockh extends My_Controller {

    public function __construct() {
        parent::__construct();
    }

    /**
     * @desc Block content
     */
    public function bsec() {
        //Params
        $sectionId = $this->_config['news_sectionid'];
        $arrInput = array(
            'sectionid' => $sectionId    //News
        );

        //Init instance
        $CI = get_instance();

        //Load section model
        $CI->load->module_model('frontend/Node_model', 'Node', TRUE);
        $resultNode = $CI->Node->nod_GetNodeBySectionID($arrInput);

        $countNode = count($resultNode);

        if ($countNode > 0) {
            $CI->load->model('frontend/article_model', 'Article', TRUE);

            foreach ($resultNode as $key => $val) {
                $arrInput['parentnode'] = $val->parentnode;
                $resultArt[$val->nodeid] = $CI->Article->arc_GetNewestByNodeId($arrInput);
            }

            echo '<pre>';
            print_r($resultArt);
        }
        print_r($resultNode);
        die('Debug');
    }

    public function sec() {
        $arrInput = array(
            'sectionid' => 45
        );
        $CI = get_instance();
        $this->load->model('frontend/section_model', 'Section', TRUE);
        $result = $this->Section->sec_GetALLSection(NULL);
        echo "<pre>";
        print_r($result);
        echo "</pre>";
        die('Debug');
    }

    public function hotnews() {
        $arrInput = array(
            'sectionid' => 45
        );
        $CI = & get_instance();
        $CI->load->model('frontend/article_model', 'Article', TRUE);
        $result = $CI->Article->arc_GetNewestArticle(NULL);
        $i = 0;
        foreach ($result as $r) {
            if ($i == 0) {
                $data['hotnews1'] = $r;
            } else if ($i == 1) {
                $data['hotnews2'] = $r;
            } else {
                $data['hotnews3'][] = $r;
            }
            if ($i++ > 6)
                break;
        }
        $this->load->view($this->_config['front_path'] . 'hotnews_view', $data);
    }

    public function videonews() {
        $arrInput = array(
            'catid' => VIDEO_CAT
        );
        $CI = & get_instance();
        $CI->load->model('frontend/article_model', 'Article', TRUE);
        $result = $CI->Article->arc_GetNewestByCate($arrInput);
        $data = $result;

        $this->load->view($this->_config['front_path'] . 'videonews_view', $data);
    }

    public function newsbyobject() {

        $CI = & get_instance();

        $CI->load->model('frontend/category_model', 'Category', TRUE);
        $CI->load->model('frontend/article_model', 'Article', TRUE);
        $cate_result = $CI->Category->sec_GetALLCategory(NULL);
        foreach ($cate_result as &$c) {
            $c->childs = $CI->Category->sec_GetCategoryByParrent(array('catid' => $c->id));
            $articles = $CI->Article->arc_GetNewestByCate(array('catid' => $c->id));
            $i = 0;
            foreach ($articles as $art) {
                if ($i == 0) {
                    $c->articles['hotnews1'] = $art;
                } else if ($i == 1) {
                    $c->articles['hotnews2'] = $art;
                } else {
                    $c->articles['hotnews3'][] = $art;
                }
                if ($i++ > 4)
                    break;
            }
        }
        $data['cate_result'] = $cate_result;
        $this->load->view($this->_config['front_path'] . 'newsbyobject_view', $data);
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */